# analyses of ABS conative outcomes (index combining all four conative variables) to investigate spillovers

##Midline ---------------------------------------------------------------------------------

absenteeism_action_ml_allcomp <- ols_main(
	outcome = "absenteeism_action",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = subset(ml, compliance == 1),
	dosage = FALSE,
	dosage_indicator = FALSE)

absenteeism_action_ml_allcomp_pvals <- get_RI_pvals(
	outcome = "absenteeism_action",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = subset(ml, compliance == 1),
	dosage = FALSE,
	dosage_indicator = FALSE,
	assignment_data = treatment_assignment,
	extract_function = coef,
	analysis_function = ols_main,
	sims = sims,
	lwr_upr_two = "upr")

absenteeism_action_ml_NT <- ols_main(
	outcome = "absenteeism_action",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = subset(ml, compliance %in% c(2,3,4)),
	dosage = FALSE,
	dosage_indicator = FALSE)

absenteeism_action_ml_NT_pvals <- get_RI_pvals(
	outcome = "absenteeism_action",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = subset(ml, compliance %in% c(2,3,4)),
	dosage = FALSE,
	dosage_indicator = FALSE,
	assignment_data = treatment_assignment,
	extract_function = coef,
	analysis_function = ols_main,
	sims = sims,
	lwr_upr_two = "upr")


absenteeism_action_ml_ITT <- ols_main(
	outcome = "absenteeism_action",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = ml,
	dosage = FALSE,
	dosage_indicator = FALSE)

absenteeism_action_ml_ITT_pvals <- get_RI_pvals(
	outcome = "absenteeism_action",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = ml,
	dosage = FALSE,
	dosage_indicator = FALSE,
	assignment_data = treatment_assignment,
	extract_function = coef,
	analysis_function = ols_main,
	sims = sims,
	lwr_upr_two = "upr")

#print robustness table with summary of ITT, TOT, Never-takers for midline --------------------------------------------------
#setup
control_means <- c("Control Mean",
	with(ml, 
	c(round(mean(absenteeism_action[absenteeism == 0 & compliance == 1],na.rm = TRUE), 2),
		round(mean(absenteeism_action[absenteeism == 0 & compliance %in% c(2,3,4)],na.rm = TRUE), 2),
		round(mean(absenteeism_action[absenteeism == 0],na.rm = TRUE), 2)
		)
	)
)


pval_lines <- c(
	"RI $p$-values",
	round(absenteeism_action_ml_allcomp_pvals$ri_pvals["absenteeism"],3),  
	round(absenteeism_action_ml_NT_pvals$ri_pvals["absenteeism"],3), 
	round(absenteeism_action_ml_ITT_pvals$ri_pvals["absenteeism"],3)
)

hypothesis_lines <- c(
	"Hypothesis",
	"upr",
	"upr",
	"upr"
)

sink("03_tables/ABS_conative_attitudes_index_spillovers.tex")
stargazer(
	... = list(
		absenteeism_action_ml_allcomp$fit,
		absenteeism_action_ml_NT$fit,
		absenteeism_action_ml_ITT$fit
	),
	type = "latex",
	p = list(
		absenteeism_action_ml_allcomp_pvals$ri_pvals,
		absenteeism_action_ml_NT_pvals$ri_pvals,
		absenteeism_action_ml_ITT_pvals$ri_pvals
	),
	se = list(
		absenteeism_action_ml_allcomp$fit_summary[,"Std. Error"],
		absenteeism_action_ml_NT$fit_summary[,"Std. Error"],
		absenteeism_action_ml_ITT$fit_summary[,"Std. Error"]
	),
	keep = "absenteeism",
	omit.stat = c("rsq","f","ser"),
	column.separate = c(3),
	column.labels = c("Conative attitudes index"),
	table.layout = "=cd#-t-as=n",
	dep.var.labels = c("Compliers","Never-Takers","All"
	),
	dep.var.labels.include = TRUE,
	multicolumn = FALSE, #to allow dependent variables to be labelled separately
	no.space = T,
	omit = "block_id",
	add.lines = list(
		control_means,
		pval_lines,
		hypothesis_lines,
		c("Block FE",
			"Yes","Yes","Yes")),
	notes.label = "",
	float = FALSE
	# style = "qje"
)
sink()


